package com.hzt.system.controller;

import com.hzt.system.common.ResultObj;
import com.hzt.system.service.LoginfoService;
import com.hzt.system.vo.LoginfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.transform.Result;
import java.util.ArrayList;
import java.util.List;

/**
*
*
* @Author:hzt
* @Date:1:38 上午 2020/7/12
*/
@RequestMapping("api/loginfo")
//@CrossOrigin
@RestController
public class LoginInfoController {

    @Autowired
    private LoginfoService loginfoService;

    @RequestMapping("loadAllLoginfo")
    public Object loadAllLoginfo(LoginfoVo loginfoVo){

        return this.loginfoService.queryAllLoginfo(loginfoVo);
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("deleteLogInfo")
    public ResultObj deleteLogInfo(Integer id){
        try {
            this.loginfoService.removeById(id);
           return ResultObj.DELETE_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }


    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("batchDeleteLogInfo")
    public ResultObj deleteLogInfo(Integer[] ids){
        try {
            if(ids.length>0&&ids!=null){
                List<Integer> idList=new ArrayList<>();
                for (Integer id : ids) {
                    idList.add(id);
                }
                this.loginfoService.removeByIds(idList);
                return ResultObj.DELETE_SUCCESS;
            }else {
                return ResultObj.DELETE_INFO;
            }
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }

    }
}
